package panel.mapPanel
{
	import assists.ButtonUtils;
	import assists.HtmlText;
	import assists.Lang;
	import assists.URI;
	import assists.log.Log;
	import assists.resource.ResourceLoader;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import inerface.IMapPanel;
	
	import main.ClientConstants;
	
	import panel.eating.DragContainerBox;
	import panel.eating.RankBtnGroupList;
	import panel.viewSpots.StaticSlide;
	
	import struct.Restaurant;
	import struct.Scenic;
	import struct.ScenicShop;
	
	public class MapPanel extends Sprite implements IMapPanel
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var back:Shape;
		private var dragContainer:DragContainerBox;
		private var visitPath:VisitPathBox;
		
		private var _onShow:Function;
		private var _onShowSysRecommend:Function;
		
		//		private var mapContainer:MapContainer;
		
		private var btnGroup:RankBtnGroupList;
		private var pathInfoList:Array;
		
		private var centerPointX:Number = 0;
		private var centerPointY:Number = 0;
		
		private var picWid:Number = 0;
		private var picHei:Number = 0;
		
		private var scaleNum:int = 12;
		
		private var _onSwapMap:Function;
		
		public function MapPanel()
		{
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang,uri:URI = null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			pathInfoList = [];
			initMap();
		}
		
		private function initMap():void
		{
			back = new Shape();
			back.graphics.beginFill(0x000000,.5);
			back.graphics.drawRect(0,_stage.stageHeight * ClientConstants.HOME_UP_PER,_stage.stageWidth,_stage.stageHeight);
			back.graphics.endFill();
			this.addChild(back);
			
			dragContainer = new DragContainerBox(_stage.stageWidth,_stage.stageHeight * .72,_stage);
			this.addChild(dragContainer);
			dragContainer.x = 0;
			dragContainer.y = _stage.stageHeight * .18;
			
			visitPath = new VisitPathBox(_stage,_loader,_lang,_uri);
			visitPath.onShowDetail = _onShow;
			visitPath.y = _stage.stageHeight * .08;
		}
		
		private function initBtnList():void
		{
			btnGroup = new RankBtnGroupList(_stage,_loader,_uri,_stage.stageWidth,_stage.stageHeight * .1);
			this.addChild(btnGroup);
			btnGroup.y = _stage.stageHeight * ClientConstants.HOME_UP_PER;
			
			var list:Array = [HtmlText.formatSizeColor("<b>查看地图</b>",0xFFFF00,20),HtmlText.formatSizeColor("<b>查看路线</b>",0xFFFF00,20)];
			
			function newShape():Shape
			{
				var btnShape:Shape = new Shape;
				btnShape.graphics.lineStyle(1,0x333333,.5);
				btnShape.graphics.beginFill(0x000000,.5);
				btnShape.graphics.drawRoundRect(0,0,_stage.stageWidth / list.length,_stage.stageHeight * .1,5);
				btnShape.graphics.endFill();
				return btnShape;
			}
			
			var btn1:ButtonUtils = new ButtonUtils(newShape(),moveToMap,list[0]);
			var btn2:ButtonUtils = new ButtonUtils(newShape(),moveToPath,list[1]);
			
			var btnList:Array = [btn2,btn1];
			btnGroup.changeData(btnList);
		}
		
		private function moveToPath():void
		{
			//			if(mapContainer){
			//				mapContainer.x = -100000;//-_stage.stageWidth;
			//				this.removeChild(mapContainer);
			//				mapContainer.clear();
			//				mapContainer = null;
			//				
			//				dragContainer.x = 0;
			//			}
		}
		
		private function moveToMap():void
		{
			//			if(!mapContainer){
			//				dragContainer.x = _stage.stageWidth;
			//				
			//				mapContainer = new MapContainer(_stage,_loader,_lang,_uri);
			//				mapContainer.initThis(_stage.stageWidth,_stage.stageHeight * .4);
			//				this.addChild(mapContainer);
			//				mapContainer.changeData(pathInfoList);
			//				mapContainer.y = _stage.stageHeight * ClientConstants.HOME_UP_PER;
			//			}
			
			if(_onSwapMap is Function){
				_onSwapMap(pathInfoList);
			}
		}
		
		public function showMap(list:Array,str:String = ""):void
		{
			if(list.length > 0){
				visitPath.titleString = str;
				visitPath.onShowSysPath = _onShowSysRecommend;
				visitPath.info = list;
				
				pathInfoList = list;
				initBtnList();
				
				//				moveToMap();
			}else{
				visitPath.titleString = str;
				visitPath.onShowSysPath = _onShowSysRecommend;
				visitPath.info = list;
				dragContainer.y = _stage.stageHeight * .08;
			}
			
			dragContainer.changeData([visitPath]);
		}
		
		public function set showDetail(func:Function):void
		{
			_onShow = func;
			visitPath.onShowDetail = _onShow;
		}
		
		public function set showSysPath(func:Function):void
		{
			_onShowSysRecommend = func;
		}
		
		public function set onSwapToMap(func:Function):void
		{
			_onSwapMap = func;
		}
		
		public function clear():void
		{
			if(_stage){
				_stage = null;
				_loader = null;
				_lang = null;
				
				//				dragContainer.clear();
				visitPath.clear();
				//				if(mapContainer){
				//					mapContainer.clear();
				//				}
			}
		}
	}
}